/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newspaperSystem.Home;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author Leo
 */
public class DeleteForm extends javax.swing.JFrame implements ActionListener {

    /**
     * Creates new form DeleteForm
     */
    private ButtonGroup btnG = new ButtonGroup();

    public DeleteForm() {
        initComponents();

        btnG.add(jRadioButton1);
        btnG.add(jRadioButton2);
        btnG.add(jRadioButton3);
        btnG.add(jRadioButton4);
        btnG.add(jRadioButton5);
        btnG.add(jRadioButton6);
        btnG.add(jRadioButton7);

        jRadioButton1.addActionListener(this);
        jRadioButton2.addActionListener(this);
        jRadioButton3.addActionListener(this);
        jRadioButton4.addActionListener(this);
        jRadioButton5.addActionListener(this);
        jRadioButton6.addActionListener(this);
        jRadioButton7.addActionListener(this);

        jButton1.addActionListener(this);
        jButton2.addActionListener(this);
        jButton3.addActionListener(this);
        jButton4.addActionListener(this);
        jButton5.addActionListener(this);
        jButton6.addActionListener(this);
        jButton7.addActionListener(this);
        jButton8.addActionListener(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        table_Delete = new javax.swing.JTable();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jToolBar1 = new javax.swing.JToolBar();
        jToolBar2 = new javax.swing.JToolBar();
        jToolBar3 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Delete Data");

        table_Delete.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        table_Delete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                table_DeleteMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(table_Delete);

        jRadioButton1.setText("Carriers");

        jRadioButton2.setText("Customers");

        jRadioButton3.setText("Products");

        jRadioButton4.setText("Bill");

        jRadioButton5.setText("Suppliers");

        jRadioButton6.setText("Routes");

        jRadioButton7.setText("Subscription");

        jToolBar1.setRollover(true);

        jToolBar2.setRollover(true);

        jToolBar3.setRollover(true);

        jButton1.setText("Carriers");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton1);

        jButton2.setText("Customers");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton2);

        jButton3.setText("Products");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton3);

        jButton4.setText("Bill");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton4);

        jButton5.setText("Suppliers");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton5);

        jButton6.setText("Routes");
        jButton6.setFocusable(false);
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton6);

        jButton7.setText("Subscription");
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton7);

        jLabel2.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N
        jLabel2.setText("Choose and click 1 button bellow to delete record");

        jButton8.setText("Back to main");

        jLabel3.setText("ID:");

        jTextField1.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton2))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton4))
                            .addComponent(jRadioButton7)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextField1))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jRadioButton5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jRadioButton6))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(71, 71, 71))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton8))
                            .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(191, 191, 191)
                                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(24, 24, 24))))))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(291, 291, 291)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton6))
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton7)
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void table_DeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_table_DeleteMouseClicked
        // TODO add your handling code here:

        Locale loc = Locale.getDefault();
        ResourceBundle bundle = ResourceBundle.getBundle("database", loc);
        String url = bundle.getString("URL");
        String user = bundle.getString("username");
        String pw = bundle.getString("password");
        String driver = bundle.getString("Driver");
        Connection conn = null;
        PreparedStatement stmt = null;
        Statement psmt = null;

        //PreparedStatement pstmnt;

        ResultSet resultSet = null;

        try {

            Class.forName(driver);
            System.out.println("Driver loaded succesfully!!!");


        } catch (ClassNotFoundException classNotFound) {

            System.out.println("OOps class not found:" + classNotFound);
        }

        try {


            conn = DriverManager.getConnection(url, user, pw);

            System.out.println("Connection successful");

            int row = table_Delete.getSelectedRow();
            String tableClick = (table_Delete.getModel().getValueAt(row, 0).toString());
            String sql1 = "Select * from Carrier where Carrier_Id='" + tableClick + "'";

            stmt = conn.prepareStatement(sql1);
            resultSet = stmt.executeQuery();

            if (resultSet.next()) {

                String id = resultSet.getString("Carrier_id");
                jTextField1.setText(id);
            }
            String sql2 = "Select * from Customer where Cust_Id='" + tableClick + "'";
            stmt = conn.prepareStatement(sql2);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("cust_id");
                jTextField1.setText(id);
            }
            String sql3 = "Select * from Product where prod_Id='" + tableClick + "'";
            stmt = conn.prepareStatement(sql3);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("prod_id");
                jTextField1.setText(id);
            }
            String sql4 = "Select * from Bill where cust_Id='" + tableClick + "'";
            stmt = conn.prepareStatement(sql4);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("cust_id");
                jTextField1.setText(id);
            }
            String sql5 = "Select * from Suppliers where supp_Id='" + tableClick + "'";
            stmt = conn.prepareStatement(sql5);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("supp_id");
                jTextField1.setText(id);
            }
            String sql6 = "Select * from Routes where route_num='" + tableClick + "'";
            stmt = conn.prepareStatement(sql6);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("route_num");
                jTextField1.setText(id);
            }
            String sql7 = "Select * from Subscription where subscr_id='" + tableClick + "'";
            stmt = conn.prepareStatement(sql7);
            resultSet = stmt.executeQuery();
            if (resultSet.next()) {

                String id = resultSet.getString("subscr_id");
                jTextField1.setText(id);
            }
        } catch (SQLException ex) {
            System.out.println("");
        } finally {

            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }

            } catch (Exception exception) {
                System.out.println("Something went wrong along the way");
            }
        }



    }//GEN-LAST:event_table_DeleteMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DeleteForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DeleteForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DeleteForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DeleteForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new DeleteForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JTable table_Delete;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        Locale loc = Locale.getDefault();
        ResourceBundle bundle = ResourceBundle.getBundle("database", loc);
        String url = bundle.getString("URL");
        String user = bundle.getString("username");
        String pw = bundle.getString("password");
        String driver = bundle.getString("Driver");
        Connection conn = null;
        PreparedStatement stmt = null;
        Statement psmt = null;

        //PreparedStatement pstmnt;

        ResultSet resultSet = null;

        try {

            Class.forName(driver);
            System.out.println("Driver loaded succesfully!!!");


        } catch (ClassNotFoundException classNotFound) {

            System.out.println("OOps class not found:" + classNotFound);
        }

        try {


            conn = DriverManager.getConnection(url, user, pw);

            System.out.println("Connection successful");

            if (e.getSource() == jRadioButton1) {

                String sqlstmt = "Select * from Carrier";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton2) {

                String sqlstmt = "Select * from Customer";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton3) {

                String sqlstmt = "Select * from Product";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton4) {

                String sqlstmt = "Select * from Bill";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton5) {

                String sqlstmt = "Select * from Suppliers";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton6) {

                String sqlstmt = "Select * from Routes";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            } else if (e.getSource() == jRadioButton7) {

                String sqlstmt = "Select * from Subscription";
                stmt = conn.prepareStatement(sqlstmt);
                resultSet = stmt.executeQuery();

                table_Delete.setModel(DbUtils.resultSetToTableModel(resultSet));
            }
            if (e.getSource() == jButton1) {
                try {
                    String deleteSearch = jTextField1.getText();

                    String sqlDel1 = "Delete  from Carrier where Carrier_Id ='" + (deleteSearch) + "'";
                    stmt = conn.prepareStatement(sqlDel1);
                    stmt.executeUpdate();
                    JOptionPane.showMessageDialog(null, "User Deleted");
                    jTextField1.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Delete from Carrier table only during normal business hours");
                }
            }
            if (e.getSource() == jButton2) {

                try {
                    String deleteSearch = jTextField1.getText();

                    String sqlDel1 = "Delete  from Customer where Cust_Id ='" + (deleteSearch) + "'";
                    stmt = conn.prepareStatement(sqlDel1);
                    stmt.executeUpdate(sqlDel1);
                    JOptionPane.showMessageDialog(null, "User Deleted");
                    jTextField1.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Delete from Customer table only during normal business hours");
                }
            } else if (e.getSource() == jButton3) {

                try {
                    String deleteSearch = jTextField1.getText();

                    String sqlDel1 = "Delete  from Product where Prod_Id ='" + (deleteSearch) + "'";
                    stmt = conn.prepareStatement(sqlDel1);
                    stmt.executeUpdate(sqlDel1);
                    JOptionPane.showMessageDialog(null, "Item  Deleted");
                    jTextField1.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Delete from Product table only during normal business hours");
                }

            } else if (e.getSource() == jButton4) {

                try {
                    String deleteSearch = jTextField1.getText();

                    String sqlDel1 = "Delete  from Bill where Cust_Id ='" + (deleteSearch) + "'";
                    stmt = conn.prepareStatement(sqlDel1);
                    stmt.executeUpdate(sqlDel1);
                    JOptionPane.showMessageDialog(null, "User Deleted");
                    jTextField1.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Delete from Bill table only during normal business hours");
                }
            } else if (e.getSource() == jButton5) {

                try {
                    String deleteSearch = jTextField1.getText();

                    String sqlDel1 = "Delete  from Suppliers where Supp_id='" + (deleteSearch) + "'";
                    stmt = conn.prepareStatement(sqlDel1);
                    stmt.executeUpdate(sqlDel1);
                    JOptionPane.showMessageDialog(null, "Item Deleted");
                    jTextField1.setText("");
                } catch (Exception ev) {

                    JOptionPane.showMessageDialog(null, "You may Delete from Suppliers table only during normal business hours");
                }

            } else if (e.getSource() == jButton6) {

                try{
                String deleteSearch = jTextField1.getText();

                String sqlDel1 = "Delete  from Routes where Route_Num ='" + (deleteSearch) + "'";
                stmt = conn.prepareStatement(sqlDel1);
                stmt.executeUpdate(sqlDel1);
                JOptionPane.showMessageDialog(null, "Item Deleted");
                jTextField1.setText("");
                 }catch(Exception ev){
                
                JOptionPane.showMessageDialog(null,"You may Delete from Routes table only during normal business hours");
            }

            } else if (e.getSource() == jButton7) {
                
                try{
                String deleteSearch = jTextField1.getText();

                String sqlDel1 = "Delete  from Subscription where Subscr_Id ='" + (deleteSearch) + "'";
                stmt = conn.prepareStatement(sqlDel1);
                stmt.executeUpdate(sqlDel1);
                JOptionPane.showMessageDialog(null, "Item Deleted");
                jTextField1.setText("");
                 }catch(Exception ev){
                
                JOptionPane.showMessageDialog(null,"You may Delete from Subscription table only during normal business hours");
            }

            }
            if (e.getSource() == jButton8) {

                this.dispose();
            }
        } catch (SQLException ex) {
            System.out.println("");
        } finally {

            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (conn != null) {
                    conn.close();
                }

            } catch (Exception exception) {
                System.out.println("Something went wrong along the way");
            }
        }

    }
}
